package com.soonoh.simplecube.cube;

public class Matrix3f {
	public static final int XX = 0;
	public static final int XY = 1;
	public static final int XZ = 2;
	public static final int YX = 3;
	public static final int YY = 4;
	public static final int YZ = 5;
	public static final int ZX = 6;
	public static final int ZY = 7;
	public static final int ZZ = 8;

	public float[] m;

	public Matrix3f() {
		this(new float[] {
				1.0f, 0.0f, 0.0f,
				0.0f, 1.0f, 0.0f,
				0.0f, 0.0f, 1.0f
		});
	}
	
	public Matrix3f(float[] m) {
		this.m = m;
	}
	
	public float XX() { return m[XX]; };
	public float XY() { return m[XY]; };
	public float XZ() { return m[XZ]; };
	public float YX() { return m[YX]; };
	public float YY() { return m[YY]; };
	public float YZ() { return m[YZ]; };
	public float ZX() { return m[ZX]; };
	public float ZY() { return m[ZY]; };
	public float ZZ() { return m[ZZ]; };
	
	public void copyTo(Matrix3f clone) {
		for (int i = 0; i < m.length; ++i) {
			clone.m[i] = this.m[i];
		}
	}
	public void multiply(Matrix3f operand) {
		Matrix3f result = new Matrix3f();
        result.m[Matrix3f.XX] = (m[XX] * operand.XX()) + (m[YX] * operand.XY()) + (m[ZX] * operand.XZ());
        result.m[Matrix3f.YX] = (m[XX] * operand.YX()) + (m[YX] * operand.YY()) + (m[ZX] * operand.YZ());
        result.m[Matrix3f.ZX] = (m[XX] * operand.ZX()) + (m[YX] * operand.ZY()) + (m[ZX] * operand.ZZ());

        result.m[Matrix3f.XY] = (m[XY] * operand.XX()) + (m[YY] * operand.XY()) + (m[ZY] * operand.XZ());
        result.m[Matrix3f.YY] = (m[XY] * operand.YX()) + (m[YY] * operand.YY()) + (m[ZY] * operand.YZ());
        result.m[Matrix3f.ZY] = (m[XY] * operand.ZX()) + (m[YY] * operand.ZY()) + (m[ZY] * operand.ZZ());

        result.m[Matrix3f.XZ] = (m[XZ] * operand.XX()) + (m[YZ] * operand.XY()) + (m[ZZ] * operand.XZ());
        result.m[Matrix3f.YZ] = (m[XZ] * operand.YX()) + (m[YZ] * operand.YY()) + (m[ZZ] * operand.YZ());
        result.m[Matrix3f.ZZ] = (m[XZ] * operand.ZX()) + (m[YZ] * operand.ZY()) + (m[ZZ] * operand.ZZ());
		result.copyTo(this);
	}
}
